home *** CD-ROM | disk | FTP | other *** search
/ Zine 8 / Zine - Issue 08 (1991-02)(Brainstorm).adf / sources / Oprint.S next >
Text File  |  2022-11-05  |  11KB  |  473 lines

  1.  
  2. ; ***************************************************
  3. ; ****                                           ****
  4. ; ****                OPRINT V1.0                ****
  5. ; ****                                           ****
  6. ; **** Func: Prints any file to the PRT: device  ****
  7. ; ****                                           ****
  8. ; ****         Written with AsmOne V1.0          ****
  9. ; ****                                           ****
  10. ; ****       By:   Orlando Budelacci             ****
  11. ; ****             Birmannsgasse 34              ****
  12. ; ****             CH-4055 Basle                 ****
  13. ; ****             Switzerland                   ****
  14. ; ****                                           ****
  15. ; ****       Published in Zine issue #8          ****
  16. ; ****                                           ****
  17. ; ****             by BRAINSTORM!                ****
  18. ; ****                ­­­­­­­­­­­                ****
  19. ; ****                                           ****
  20. ; **** As always: 100% pc-relative               ****
  21. ; ****            (like every program should be!)****
  22. ; ****                                           ****
  23. ; **** Note: Don't start from the Assembler!     ****
  24. ; ****                                           ****
  25. ; **** Note2: Program breaks after a few seconds ****
  26. ; ****        if no printer is connected. By the ****
  27. ; ****        way, if anyone knows how to check  ****
  28. ; ****        fast, if there is a printer        ****
  29. ; ****        connected, please contact me!      ****
  30. ; ****        BUT no hardware access routines!   ****
  31. ; ****                                           ****
  32. ; ***************************************************
  33.  
  34. ;Exec
  35. AllocMem       = -198
  36. Freemem        = -210
  37. Findtask       = -294
  38. AllocSignal    = -330
  39. AddPort        = -354
  40. RemPort        = -360
  41. OpenLib        = -408
  42. CloseLib       = -414
  43. OpenDev        = -444
  44. CloseDev       = -450
  45. Doio           = -456
  46.  
  47. ;Dos
  48. Open           = -30
  49. Close           = -36
  50. Read           = -42
  51. Write            = -48
  52. Output         = -60
  53. Examine        = -102
  54. IoErr           = -132
  55. Lock           = -84
  56.  
  57. ;Mem-Types
  58. Public           = $1
  59. Clear           = $10000
  60. Chip           = $2
  61.  
  62. SysBase: macro
  63.     move.l    4.w,a6
  64. endm
  65.  
  66. start:
  67.  
  68. ; -------------------------------------
  69. ; ----         PARAMETERS          ----
  70. ; -------------------------------------
  71.  
  72.     cmp.b    #1,d0
  73.     bne.s    parameter
  74.     lea    parflag(pc),a5
  75.     move.b    #1,(a5)
  76.     bra.s    open_dos
  77.  
  78. parameter:
  79.  
  80. Filename_search:
  81.     movem.l    d0/a0,-(sp)             ;save parameters given from
  82.                                         ;system
  83.  
  84. ; -------------------------------------
  85. ; ---- ALLOCMEM FOR FILENAME BUFFER ---
  86. ; -------------------------------------
  87.  
  88.     SysBase
  89.     move.l    #255,d0                 ;amount of memory
  90.     move.l    #Clear+Public,d1
  91.     jsr    AllocMem(a6)
  92.     lea    filebuffer(pc),a2
  93.     move.l    d0,(a2)
  94.  
  95.     movem.l    (sp)+,d0/a0
  96.     lea    filebuffer(pc),a2
  97.         tst.l   (a2)
  98.         beq.L   error
  99.  
  100. ; -------------------------------------
  101. ; ----  COPY FILENAME IN BUFFER    ----
  102. ; -------------------------------------
  103.  
  104.     subq.l    #2,d0
  105.     move.l    filebuffer(pc),a3
  106. copyname:
  107.     move.b    (a0)+,(a3)+
  108.     dbf    d0,copyname
  109.  
  110. ; -------------------------------------
  111. ; ----       OPEN DOS LIBRARY      ----
  112. ; -------------------------------------
  113.  
  114. open_dos:
  115.     SysBase
  116.     lea     dosname(pc),a1
  117.      jsr     -408(a6)        ;OpenLib
  118.     lea    dosbase(pc),a3
  119.      move.l    d0,(a3)
  120.     beq.L    error
  121.  
  122. ; -------------------------------------
  123. ; ----       GET OUTPUT HANDLE     ----
  124. ; -------------------------------------
  125.  
  126. get_output:
  127.     move.l     d0,a6
  128.     jsr    OutPut(a6)
  129.     lea    windowhandle(pc),a3
  130.     move.l    d0,(a3)
  131.     beq.L    error
  132.  
  133. ; *** Put text in window ***
  134. ; *** if no filename was specified at start of program then ***
  135. ; *** print out 'how to use' text ***
  136.  
  137. put_text:
  138.     lea    parflag(pc),a3
  139.     tst.b    (a3)
  140.     beq.s    file_name_found
  141.     lea    info_text(pc),a1
  142.     bsr.L    print
  143.     bra.L    close_dos_lib
  144.  
  145. file_name_found:
  146.     lea    text(pc),a1
  147.     bsr.L    print
  148.  
  149. ; -------------------------------------
  150. ; ----          OPEN FILE          ----
  151. ; -------------------------------------
  152.  
  153. Open_file:
  154.     move.l    filebuffer(pc),d1
  155.     move.l     #1005,d2
  156.      jsr     -30(a6)            ;OpenFile
  157.     lea    handle(pc),a2
  158.     move.l     d0,(a2)
  159.     beq.L    error
  160.  
  161. ; -------------------------------------
  162. ; ----     ALLOCMEM INFOBLOCK      ----
  163. ; -------------------------------------
  164.  
  165. Allocmem_Infoblock:
  166.     SysBase
  167.     move.l    #260,d0
  168.     move.l    #Clear+Chip,d1
  169.     jsr    AllocMem(a6)
  170.     lea    infoblock(pc),a2
  171.     move.l    d0,(a2)
  172.     beq.L    error
  173.  
  174. ; -------------------------------------
  175. ; ----      CREAT FILE LOCK        ----
  176. ; -------------------------------------
  177.  
  178. Create_Lock:
  179.     move.l    dosbase(pc),a6
  180.     move.l    filebuffer(pc),d1
  181.     moveq    #-2,d2                  ;modus = read
  182.     jsr    Lock(a6)        
  183.     lea    locksave(pc),a2
  184.     move.l    d0,(a2)
  185.     beq.L    error
  186.  
  187. ; -------------------------------------
  188. ; ----            EXAMINE          ----
  189. ; -------------------------------------
  190.  
  191. X_amine:
  192.     move.l    locksave(pc),d1
  193.     move.l    infoblock(pc),d2
  194.     jsr    Examine(a6)
  195.  
  196. ; -------------------------------------
  197. ; ----            UNLOCK           ----
  198. ; -------------------------------------
  199.  
  200. Un_lock:
  201.     move.l    locksave(pc),d1
  202.     jsr    -90(a6)
  203.  
  204. ; -------------------------------------
  205. ; ----      GET LENGTH OF FILE      ----
  206. ; -------------------------------------
  207.  
  208. Get_Length:
  209.     move.l    infoblock(pc),a2
  210.     move.l    124(a2),d0        ;at offset 124 from the
  211.     lea    length(pc),a2           ;start of infoblock
  212.     move.l    d0,(a2)                 ;is the length of the program
  213.  
  214. ; -------------------------------------
  215. ; ----  ALLOCATE MEMORY FOR FILE   ----
  216. ; -------------------------------------
  217.  
  218. Alloc_file_mem:
  219.     SysBase
  220.     moveq    #Public,d1
  221.     jsr    AllocMem(a6)        ;allocmem
  222.     lea    startaddr(pc),a0
  223.     move.l    d0,(a0)
  224.     beq.L    alloc_error
  225.  
  226. ; -------------------------------------
  227. ; ----        LOAD THE FILE        ----
  228. ; -------------------------------------
  229.  
  230. Read_file:
  231.     move.l    dosbase(pc),a6
  232.      move.l     handle(pc),d1
  233.     move.l     startaddr(pc),d2    ;start of memory block
  234.      move.l     length(pc),d3        ;length of file to load
  235.      jsr     Read(a6)        ;ReadFile
  236.  
  237. ; -------------------------------------
  238. ; ----        CLOSE THE FILE       ----
  239. ; -------------------------------------
  240.  
  241. Close_file:
  242.     move.l    handle(pc),d1
  243.      jsr     Close(a6)        ;Close File
  244.  
  245.     lea    file_loaded(pc),a1
  246.     bsr.L    print
  247.  
  248.  
  249. ; -------------------------------------
  250. ; ----       PRINT ROUTINE         ----
  251. ; -------------------------------------
  252.  
  253. OOpen_prt:
  254.     move.l    dosbase(pc),a6
  255.     lea    Oprtname(pc),a1
  256.     move.l    a1,d1
  257.     move.l    #1006,d2    ;modus = write new
  258.     jsr    Open(a6)    
  259.     lea    Oprthandle(pc),a2        
  260.     move.l    d0,(a2)
  261.     bne.s    Owrite        
  262.  
  263. ;* ! *
  264.  
  265.     lea    printer_error(pc),a1
  266.     bsr.L    print
  267.     bra.s    end_printer
  268.  
  269. OWrite:
  270.     lea    printing_text(pc),a1
  271.     bsr.L    print
  272.  
  273.     move.l    dosbase(pc),a6    
  274.     move.l    Oprthandle(pc),d1    ;Datei-Identifikation
  275.     move.l    startaddr(pc),d2    ;zeiger auf Daten-Puffer
  276.                     ;alloc-mem range
  277.     move.l    length(pc),d3        ;laenge in bytes    
  278.     jsr    Write(a6)        ;Printen!!!
  279.  
  280. OClose_prt:
  281.     move.l    dosbase(pc),a6
  282.     move.l    Oprthandle(pc),d1
  283.     jsr    Close(a6)
  284.  
  285. ; -------------------------------------
  286. ; ----    PRINT 'FINISH' MESSAGE   ----
  287. ; -------------------------------------
  288.  
  289. end_really:
  290.     lea    end_text(pc),a1
  291.     bsr.S    print
  292.  
  293. End_printer:
  294.  
  295. closeend:
  296.     SysBase
  297.     move.l    startaddr(pc),a1
  298.     move.l    length(pc),d0
  299.     jsr    FreeMem(a6)
  300.  
  301.     move.l    infoblock(pc),a1
  302.     move.l    #260,d0
  303.     jsr    FreeMem(a6)
  304.  
  305. ; -------------------------------------
  306. ; ----     CLOSE DOS LIBRARY?      ----
  307. ; -------------------------------------
  308.  
  309. Close_dos_lib:
  310.     SysBase
  311.     lea    filebuffer(pc),a2
  312.     tst.l    (a2)
  313.     beq.s    closedoslib
  314.  
  315. ; -------------------------------------
  316. ; ----       FREE FILE BUFFER      ----
  317. ; -------------------------------------
  318.  
  319. free:    move.l    filebuffer(pc),a1
  320.     moveq    #0,d0
  321.     add.w    #255,d0
  322.     jsr    FreeMem(a6)
  323.  
  324. ; -------------------------------------
  325. ; ----     CLOSE DOS LIBRARY        ----
  326. ; -------------------------------------
  327.  
  328. closedoslib:
  329.     move.l    dosbase(pc),a1
  330.     jsr    CloseLib(a6)    ;CloseLib
  331.  
  332. Exit:    moveq    #0,d0
  333.      rts
  334.  
  335.  
  336. ; -------------------------------------
  337. ; ----         FILE ERRORS         ----
  338. ; -------------------------------------
  339.  
  340. error:
  341.     move.l    dosbase(pc),a6
  342.     jsr    IoErr(a6)
  343.     cmp.l    #205,d0
  344.     bne.S    msg2
  345.     lea    filenotfound(pc),a1
  346.     bsr.S    print
  347.  
  348. msg2:
  349.     moveq    #103,d7
  350.     cmp.l    d7,d0
  351.     bne.S    msg3
  352.     bra.s    alloc_error
  353.         
  354. msg3:
  355.     moveq    #0,d0
  356.     bra.s    close_dos_lib        
  357.  
  358.  
  359. ; -------------------------------------
  360. ; ----   NOT ENOUGH MEMORY ERROR   ----
  361. ; -------------------------------------
  362.  
  363. alloc_error:
  364.     lea    memoryerror(pc),a1
  365.     bsr.S    print
  366.     bra.s    closeend        
  367.  
  368. ; -------------------------------------
  369. ; ----    PRINT TEXT ROUTINE       ----
  370. ; -------------------------------------
  371.  
  372. ; * Prints any ascii text in the current window           *
  373. ; * Dosbase must be in label >>> dosbase <<<              *
  374. ; * Pointer to text must be in >>> a1 <<<                 *
  375. ; * Output handle must be stored in >>> windowhandle <<<< *
  376. ; * all registers saved and written back                  *
  377.  
  378. print:
  379.     movem.l    d0-d3/a1/a6,-(sp)
  380.     move.l    a1,d2            ;pointer to text
  381.     moveq    #0,d3            ;counter for chars
  382.  
  383. endsearch:                ;end of text=$00
  384.     tst.b    (a1)+
  385.     beq.s    EndFound
  386.     addq.l    #1,d3
  387.     bra.s    endsearch
  388.  
  389. Endfound:
  390.     move.l    windowhandle(pc),d1
  391.     move.l    dosbase(pc),a6    
  392.     jsr    Write(a6)
  393.     movem.l    (sp)+,d0-d3/a1/a6
  394.     rts
  395.  
  396. ; -------------------------------------
  397. ; ----       ASCII MESSAGES        ----
  398. ; -------------------------------------
  399.  
  400. text:
  401. dc.b    $a
  402. dc.b    $9b,'1;33;40m'
  403. dc.b    'OPrint V1.01',$a
  404. dc.b    $9b,'0;31;40m'
  405. dc.b    'By Orlando Budelacci, December 1990, Public domain.',$a,0
  406. textend:
  407. info_text:
  408. dc.b    $9b,'1;33;40m'
  409. dc.b    'OPrint V1.01',$a
  410. dc.b    $9b,'0;31;40m'
  411. dc.b    'By Orlando Budelacci, December 1990, Public domain.',$a
  412. dc.b    'Prints any file to the PRT: device',$a,$a
  413. dc.b    'The source of this program was published in '
  414. dc.b    $9b,'0;33;40m'
  415. dc.b    'ZINE #8 by BRAINSTORM.',$a
  416. dc.b    $9b,'0;31;40m',$a
  417. dc.b    'Usage: OPrint [filename]',$a,$a
  418. dc.b    'By:',$a
  419. dc.b    '    Orlando Budelacci',$a
  420. dc.b    '    Birmannsgasse 34',$a
  421. dc.b    '    CH-4055 Basle',$a,$a
  422. dc.b    0
  423.  
  424. printer_error:
  425. dc.b     'Printer-trouble!!!',$a,$a
  426. dc.b    'Make sure that the following files are on the disk:',$a
  427. dc.b     'devs/printer.device',$a
  428. dc.b     'devs/parallel.device',$a
  429. dc.b     'devs/printers/[generic]',$a
  430. dc.b     'devs/system-configuration',$a
  431. dc.b     'l/port-handler',$a,$a
  432. dc.b    $9b,$20,$70      ;visible cursor
  433. dc.b     0
  434.  
  435. file_loaded:
  436. dc.b    $9b,$30,$20,$70    ;invisible cursor
  437. dc.b    'File loaded...',$a
  438. dc.b    'Trying to set up devices and handler...',0
  439.  
  440. printing_text:
  441. dc.b    'Ok! Devices and handler loaded.',$a,$a
  442. dc.b    'PRINTING... be patient.',$a,0
  443.  
  444. end_text:
  445. dc.b    'Finished!',$a,$a
  446. dc.b    $9b,$20,$70      ;visible cursor
  447.  
  448. dc.b    0
  449.  
  450. dosname:    dc.b     'dos.library',0
  451.         even
  452. filenotfound:    dc.b    'File not found!',$a,$a,0
  453. memoryerror:    dc.b    'Not enough memory!',$a,$a,0
  454. even
  455.  
  456.  
  457. ; -------------------------------------
  458. ; ----    HANDLES, POINTERS        ----
  459. ; -------------------------------------
  460.  
  461. filebuffer:    dc.l    0
  462. Handle:        dc.l     0
  463. Dosbase:    dc.l    0
  464. Windowhandle:    dc.l    0
  465. Locksave:    dc.l    0
  466. length:        dc.l    0
  467. startaddr:    dc.l    0
  468. infoblock:    dc.l    0
  469. Oprtname:    dc.b    'PRT:',0
  470. parflag:    dc.b    0
  471. even
  472. Oprthandle:    dc.l    0
  473.